//
//  weixin.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/9/6.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "weixin.h"

@implementation weixin
- (void)onResp:(BaseResp*)resp{
    __weak __typeof(self)weakSelf = self;

    //微信支付
    if([resp isKindOfClass:[PayResp class]]){
        //支付返回结果，实际支付结果需要去微信服务器端查询
        switch (resp.errCode) {
            case WXSuccess:{
                //微信支付
                [[NSNotificationCenter defaultCenter] postNotificationName:@"微信支付成功" object:nil userInfo:nil];
            }
            break;

            default:
                NSLog(@"错误，retcode = %d, retstr = %@", resp.errCode,resp.errStr);
                if (resp.errCode == -2) {
//                    ShowMessage(@"用户中途取消");
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"微信支付用户中途取消" object:nil userInfo:nil];
                }else{
//                    ShowMessage(@"支付失败");
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"微信支付用户支付失败" object:nil userInfo:nil];
                }
                break;
        }
    }

    //微信登录
    if ([resp isKindOfClass:[SendAuthResp class]]){
        SendAuthResp *rep = (SendAuthResp *)resp;
        if (rep.errCode == 0) {
//            [[NSNotificationCenter defaultCenter] postNotificationName:WXLoginSuccess object:@{@"WXLoginCode":rep.code}];
        }
    }
}
//微信SDK自带的方法，处理从微信客户端完成操作后返回程序之后的回调方法,显示支付结果的
//-(void) onResp:(BaseResp*)resp
//{
//    //启动微信支付的response
//    NSString *payResoult = [NSString stringWithFormat:@"errcode:%d", resp.errCode];
//    if([resp isKindOfClass:[PayResp class]]){
//        //支付返回结果，实际支付结果需要去微信服务器端查询
//        switch (resp.errCode) {
//            case 0:
//            {
//                payResoult = @"支付结果：成功！";
//                NSDictionary *dict =@{@"key":@"2"};
//                NSNotification *notification =[NSNotification notificationWithName:@"支付成功success" object:nil  userInfo:dict];
//                [[NSNotificationCenter defaultCenter] postNotification:notification];
//            }
//                break;
//            case -1:
//                payResoult = @"支付结果：失败！";
//                break;
//            case -2:
//            {
//                payResoult = @"用户已经退出支付！";
//
//            }
//                break;
//            default:
//                payResoult = [NSString stringWithFormat:@"支付结果：失败！retcode = %d, retstr = %@", resp.errCode,resp.errStr];
//                break;
//        }
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"支付结果" message:payResoult delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//        [alert show];
//    }
//}


@end
